package com.talent.core.protocol.mqtt.model.fix;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

/**
 * @ClassName：TlMqttFixedHead
 * @Author: hszhou
 * @Date: 2024/11/25 11:08
 * @Description: mqtt的固定头部信息
 */

public class TlMqttFixedHead {
    private final static Logger logger = LoggerFactory.getLogger(TlMqttFixedHead.class);

    /**这是第1个完整字节*/
    private int type;
    /**消息类型*/
    private int messageType;
    /**消息长度*/
    private int length;

    /**重发标志位 0 是新消息  1肯能是重发*/
    private int dup;
    /**qos的等级*/
    private int qos;
    /**是否保留消息*/
    private int retain;

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getMessageType() {
        return messageType;
    }

    public void setMessageType(int messageType) {
        this.messageType = messageType;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getDup() {
        return dup;
    }

    public void setDup(int dup) {
        this.dup = dup;
    }

    public int getQos() {
        return qos;
    }

    public void setQos(int qos) {
        this.qos = qos;
    }

    public int getRetain() {
        return retain;
    }

    public void setRetain(int retain) {
        this.retain = retain;
    }

    public void logging(){

        logger.info("消息类型是【{}】，剩余长度【{}】，dup是【{}】，qos是【{}】，retain是【{}】"
                ,messageType,length,dup,qos,retain);
    }


    @Override
    public String toString() {
        return "TlMqttFixedHead{" +
                "type=" + type +
                ", messageType=" + messageType +
                ", length=" + length +
                ", dup=" + dup +
                ", qos=" + qos +
                ", retain=" + retain +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TlMqttFixedHead that = (TlMqttFixedHead) o;
        return type == that.type && messageType == that.messageType && length == that.length && dup == that.dup && qos == that.qos && retain == that.retain;
    }

    @Override
    public int hashCode() {
        return Objects.hash(type, messageType, length, dup, qos, retain);
    }
}
